package com.noble.glamour.ui;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;

import com.noble.glamour.module.logic.application.App;
import com.noble.glamour.module.logic.application.ModuleMgr;
import com.noble.library.base.BaseActivity;
import com.noble.glamour.module.util.PermissionUtils;
import com.noble.glamour.module.util.UIShow;
import com.noble.glamour.ui.start.NavUserAct;
import com.noble.library.location.LocationMgr;
import com.noble.library.observe.MsgMgr;

/**
 * 闪屏页面
 */
public class SplashActivity extends BaseActivity {
    private final static long delayTime = 2000;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        isCanBack(false);
        setCanNotify(false);//设置该页面不弹出悬浮窗消息通知
        super.onCreate(savedInstanceState);

        init();
    }

    private void init() {
        initData();
        PermissionUtils.requestPermission(this);//启动时先请求音视频权限

        int delay = (int) (delayTime - (System.currentTimeMillis() - App.t));
        MsgMgr.getInstance().delay(new Runnable() {
            @Override
            public void run() {
                skipLogic();
            }
        }, delay);
    }

    private void initData() {
        LocationMgr.getInstance().start();//启动定位
        ModuleMgr.getCommonMgr().updateUsers();//软件升级U-P读取
        ModuleMgr.getCommonMgr().requestStaticConfig();//请求一些在线配置信息
    }

    /**
     * Intent跳转
     */
    private void skipLogic() {
        if (ModuleMgr.getLoginMgr().checkAuthIsExist()) {
            UIShow.showMainClearTask(SplashActivity.this);
        } else {
            Intent intent = new Intent(SplashActivity.this, NavUserAct.class);
            startActivity(intent);
            finish();
        }
    }

    @Override
    public void onBackPressed() {
        // 空实现，不响应返回键点击
    }
}
